package com.example.administrator.printoutindemo;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.example.administrator.printoutindemo.mvp.ui.activity.DaiShenPiXiangQingActivity;

import java.util.List;


public class StoreSubmitProjectListAdapter extends BaseAdapter {
    private Context mContext = null;
    private LayoutInflater mInflater = null;

    private List<OutStorageListlInfo> li_outstorage = null;

    private class ViewHolder {
        TextView s_ada_sub_list_bid;
        TextView s_ada_sub_list_projectname;
        TextView s_ada_sub_list_material;
        TextView s_ada_sub_list_loginName;
        TextView s_ada_sub_list_loginPwd;
        TextView tv_ling_liao_ren;
        TextView tv_ling_liao_ren_dian_hua;
        LinearLayout ll_item;

    }

    private ViewHolder holder = null;

    public StoreSubmitProjectListAdapter(Context context) {
        // TODO Auto-generated constructor stub
        mContext = context;
    }

    public void setList(List<OutStorageListlInfo> li_outstorage) {

        this.li_outstorage = li_outstorage;

        this.mInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub

        int result = 0;
        if (null != li_outstorage) {
            result = li_outstorage.size();
        }
        return result;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        Object result = null;
        if (null != li_outstorage) {
            result = li_outstorage.get(position);
        }

        return result;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        int result = 0;
        if (null != li_outstorage) {
            result = li_outstorage.size();
        }
        return result;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        if (convertView == null) {

            holder = new ViewHolder();

            convertView = mInflater.inflate(R.layout.item_ling_liao_shen_qing_ji_lu,
                    null);
            holder.ll_item = (LinearLayout) convertView
                    .findViewById(R.id.ll_item);
            holder.tv_ling_liao_ren = (TextView) convertView
                    .findViewById(R.id.tv_ling_liao_ren);
            holder.tv_ling_liao_ren_dian_hua = (TextView) convertView
                    .findViewById(R.id.tv_ling_liao_ren_dian_hua);
            holder.s_ada_sub_list_bid = (TextView) convertView
                    .findViewById(R.id.s_ada_sub_list_bid);
            holder.s_ada_sub_list_projectname = (TextView) convertView
                    .findViewById(R.id.s_ada_sub_list_projectname);
            holder.s_ada_sub_list_material = (TextView) convertView
                    .findViewById(R.id.s_ada_sub_list_material);
            holder.s_ada_sub_list_loginName = (TextView) convertView
                    .findViewById(R.id.s_ada_sub_list_loginName);
            holder.s_ada_sub_list_loginPwd = (TextView) convertView
                    .findViewById(R.id.s_ada_sub_list_loginPwd);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (null != this.li_outstorage) {

            OutStorageListlInfo c = li_outstorage.get(position);

            holder.s_ada_sub_list_bid.setText(c.get_out_storagelist_batchid());
            holder.s_ada_sub_list_projectname.setText(c.get_projectname());
            holder.s_ada_sub_list_material.setText(c.get_material());
            holder.s_ada_sub_list_loginName.setText(c.get_receive_loginName());
            holder.s_ada_sub_list_loginPwd.setText(c.get_receive_loginPwd());
            holder.tv_ling_liao_ren.setText(c.getReceive_userName() == null ? "" : c.getReceive_userName());
            holder.tv_ling_liao_ren_dian_hua.setText(c.getReceive_userPhone() == null ? "" : c.getReceive_userPhone());

            holder.ll_item.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent in = new Intent();
                    Bundle bunl = new Bundle();
                    bunl.putString("outCheckProject", c.get_out_storagelist_batchid());
                    in.putExtras(bunl);
                    in.setClass(mContext, DaiShenPiXiangQingActivity.class);
                    mContext.startActivity(in);
                }
            });
        }

        return convertView;
    }
}